<?php

require('./pagestart.php');

if (isset($_GET['pane']) && $_GET['pane'] == 'left')
{
	if (!$module = CACHE('ts_cache')->get('admin_module'))
	{
		$dir = @opendir('.');
		$setmodules = 1;
		while ($file = @readdir($dir))
		{
			if (preg_match('/^admin_.*?\.php$/', $file))
			{
				include('./' . $file);
			}
		}
		unset($setmodules);
		@closedir($dir);
		CACHE('ts_cache')->set('admin_module', $module, 600);
	}
	
	$template->assign_vars(array(
		'TPL_ADMIN_NAVIGATE' => true,
		'U_FORUM_INDEX'      => '../index.php',
		'U_ADMIN_INDEX'      => 'index.php?pane=right',
	));
	
	ksort($module);
	
	while (list($cat, $action_array) = each($module))
	{
		$cat = (!empty($lang[$cat])) ? $lang[$cat] : preg_replace('/_/', ' ', $cat);
		$template->assign_block_vars('catrow', array(
			'ADMIN_CATEGORY' => $cat,
		));
		ksort($action_array);
		$row_count = 0;
		while (list($action, $file) = each($action_array))
		{
			$row_class = !($row_count % 2) ? 'row1' : 'row2';
			$action = (!empty($lang[$action])) ? $lang[$action] : preg_replace('/_/', ' ', $action);
			
			$template->assign_block_vars('catrow.modulerow', array(
				'ROW_CLASS' => $row_class,
				'ADMIN_MODULE' => $action,
				'U_ADMIN_MODULE' => $file,
			));
			
			$row_count++;
		}
	}
}
elseif (isset($_GET['pane']) && $_GET['pane'] == 'right')
{
	$template->assign_vars(array(
		'TPL_ADMIN_MAIN'  => true,
		'ADMIN_LOCK'      => ($ts_cfg['board_disable']) ? true : false,
	));
	
		$template->assign_vars(array(
			'GZIP_COMPRESSION' => ($ts_cfg['gzip_compress']) ? $lang['ON'] : $lang['OFF'],
	));
}
else
{
	// Generate frameset
	$template->assign_vars(array(
		'CONTENT_ENCODING'   => $ts_cfg['lang'][$userdata['user_lang']]['encoding'],
		'TPL_ADMIN_FRAMESET' => true,
	));
	send_no_cache_headers();
	print_page('index.tmpl', 'admin', 'no_header');
}

print_page('index.tmpl', 'admin');

// Functions
function inarray ($needle, $haystack)
{
	for ($i = 0; $i < sizeof($haystack); $i++)
	{
		if ($haystack[$i] == $needle)
		{
			return true;
		}
	}
	return false;
}